<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Index extends Site {

    function setup() {
        $this->run_modes('list', 'clear');
        $this->start_mode('list');
        $this->selfurl = '/index.php';
        parent::setup();
        include("common.php");
    }

    function cgiapp_prerun($rm='') {
        $this->Product = getModel('Model_Product');
        $this->indexBanner = getModel('Model_indexBanner');
        parent::cgiapp_prerun();
    }

    function action_list() {
        $kvcobj = getCache('index_list', array('expire' =>KVC_EXPIRE));

        //最新邀請
        $invite_new_list = $kvcobj->get('invite_new_list');
        if (!$invite_new_list) {
            $invite_new_list = $this->Product->get_new_invite_list();
            $kvcobj->set('invite_new_list', $invite_new_list);
        }
//echo '<pre>'.var_export($invite_new_list,1).'</pre>'; exit;
        //提交報告
        $submit_report_list = $kvcobj->get('submit_report_list');
        if (!$submit_report_list) {
            $submit_report_list = $this->Product->get_submit_report_list();
            $kvcobj->set('submit_report_list', $submit_report_list);
        }

        //最新報告
        $new_report_list = $kvcobj->get('new_report_list');
        if (!$new_report_list) {
            $new_report_list = $this->Product->get_new_report_list();
            $kvcobj->set('new_report_list', $new_report_list);
        }

        //彈出層 本周最新邀請
        /* $data6[1] = $this->Product->getProductList(1,1,"TB1.apply_starttime desc",1,6);
          $data6[2] = $this->Product->getProductList(5,1,"TB1.apply_starttime desc",1,6);
          foreach($data6 as $k => $v){
          foreach($v['result'] as $k1 => $v1){
          $data6[$k]['result'][$k1]['_difTime'] = str_diff_time($v1['report_starttime']);
          $data6[$k]['result'][$k1]['_photo_url'] = PhotoResize($v1['cover'],120,120);
          }
          } */

        /**
          $data6 = $this->Product->getProductList(0,1,"TB1.apply_starttime desc",1,8,"",0,1);
          foreach($data6['result'] as $k1 => $v1){
          $data6['result'][$k1]['_difTime'] = explode(" ",str_diff_time($v1['apply_endtime']));
          $data6['result'][$k1]['_photo_url'] = PhotoResize($v1['cover'],158,158);
          $data6['result'][$k1]['name'] = wordscut($v1['name'],11);
          $data6['result'][$k1]['cname'] = wordscut($v1['cname'],11);
          }

          if(!isset($_COOKIE["index_invite_box"]) || empty($_COOKIE["index_invite_box"])){
          setcookie("index_invite_box",1, time()+24*60*60*1);//cookie有效期300秒
          $_is_invite_box = 1;
          }else{ $_is_invite_box = 0;}

         * */
        //首頁flash數組
        $flash = $kvcobj->get('flash');
        if (!$flash) {
            $flash = $this->indexBanner->getindexBanner();
            $kvcobj->set('flash', $flash);
        }
        //echo '<pre>'.var_export($flash,1).'</pre>';
        $this->tmpl_assign('flash', $flash);
        $this->tmpl_assign('isindex', 1);
        $this->tmpl_assign('invite_new_list', $invite_new_list);
        $this->tmpl_assign('submit_report_list', $submit_report_list['result']);
        $this->tmpl_assign('new_report_list', $new_report_list['result']);
        //$this->tmpl_assign('data5',$data5);
        return $this->load_tmpl('index.php');
    }

    function action_clear() {
        $kvc = trim($this->get_q('kvc', ''));
        clear_kvcache($kvc);
    }


}

$webapp = new Index();
$webapp->run();
?>
